package edu.student.models;

import java.util.ArrayList;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import com.util.DB;
/**
Author: Satya Deepthi Bhagi
 **/
public class Friend {
	private String rollNo;
	private String friendName;
	private String friendRollNo;
	private String friendImage;
	
	public static ArrayList<Friend> find(String selectionModifier) {
		ArrayList<Friend> selection = new ArrayList<Friend>();
		ResultSet resultSet = null;
		String query = "select USER_NAME, FRIEND_ROLL_NO,image from Friend f, user u " + selectionModifier +"  and u.roll_no=f.friend_roll_no" ;
		Connection connection = DB.getConnection();
		resultSet = DB.readFromDB(query, connection);
		try {
			while (resultSet.next()) {
				Friend friend = new Friend();
				friend.friendName = resultSet.getString("USER_NAME");
				friend.friendRollNo = resultSet.getString("FRIEND_ROLL_NO");
				friend.friendImage = resultSet.getString("image");
				selection.add(friend);
		
			}
		} catch (SQLException e) {
	       System.out.println("Exception while reading from db"+ e);
		}
		DB.close(connection);
		return selection;
	}

	public String getFriendName() {
		return friendName;
	}

	public void setFriendName(String friendName) {
		this.friendName = friendName;
	}

	public String getFriendRollNo() {
		return friendRollNo;
	}

	public void setFriendRollNo(String friendRollNo) {
		this.friendRollNo = friendRollNo;
	}

	public String getFriendImage() {
		return friendImage;
	}

	public void setFriendImage(String friendImage) {
		this.friendImage = friendImage;
	}
public String getRollNo() {
		return rollNo;
	}
	public void setRollNo(String rollNo) {
		this.rollNo = rollNo;
	}

}
